# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def addTwoNumbers(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        if not l1 and not l2:
            return None
        
        val = (0 if not l1 else l1.val) + (0 if not l2 else l2.val)
        next1 = None if not l1 else l1.next
        next2 = None if not l2 else l2.next
            
        if val >= 10:
            if not next1:
                next1 = ListNode(1)
            else:
                next1.val += 1    
        
        node = ListNode(val % 10)
        node.next = self.addTwoNumbers(next1, next2)
            
        return node
